package com.mis.clothespos.clothes.controller;




import com.mis.clothespos.clothes.domain.clothes;
import com.mis.clothespos.clothes.service.IclothesService;
import com.mis.clothespos.common.AjaxResult;
import com.mis.clothespos.common.BaseController;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clothes")
public class ClothesController extends BaseController {

    @Autowired
    IclothesService c_service;






    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(clothes clothes)
    {
        return toAjax(c_service.insert(clothes));
    }
    /**
    * @Description: 根据id查询衣服
    * @Param:  主键id
    * @return:  clothes
    * @Author: 黄海滨
    * @Date:
    */
    @RequiresPermissions("user:view")
    @GetMapping("/selectClothes")
    @ResponseBody
    public AjaxResult selectClothes(clothes c){
        AjaxResult result = new AjaxResult();
        List<clothes> clothes=c_service.getClothes(c);
        result.put("clothes",clothes);
        result.put("total",clothes.size());


        return result;

    }

    @GetMapping("/selectById")
    @ResponseBody
    public AjaxResult selectById(Integer id){
        System.out.println(id);
        AjaxResult result=new AjaxResult();
        clothes c=c_service.selectById(id);
        result.put("msg","添加成功");
        result.put("code",200);
        result.put("clothes",c);
        return result;

    }
    /**
    * @Description: 根据用户提供条件查询库存
    * @Param:  clothes
    * @return:  List<clothes>
    * @Author: 黄海滨
    * @Date:
    */
    @GetMapping("/checkStore")
    @ResponseBody
    public List<clothes> checkStore(clothes detail){
        return  c_service.checkStore(detail);
    }


    /**
    * @Description:根据用户提供的条件更新clothes表
    * @Param:  clothes
    * @return:  AjaxResult
    * @Author: 黄海滨
    * @Date:
    */
    @PostMapping( "/updateClothes")
    @ResponseBody
    public AjaxResult updateClothes(clothes record)
    {

        return toAjax(c_service.updateByPrimaryKeySelective(record));
    }

    /**
    * @Description:
    * @Param:
    * @return:
    * @Author: 黄海滨
    * @Date:
    */
    @PostMapping("removeClothesById")
    @ResponseBody
    public AjaxResult removeClothesById(Integer id){

        return toAjax(c_service.deleteByPrimaryKey(id));
    }






}
